package smallchange.oop;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class SmallChangeSysoop {
    Scanner myscanner = new Scanner(System.in);
    String key = "";
    //        2.零钱通明细
    // (1)可以把收益入账和消费，保存到数组(2)可以使用对象(3)简单的话可以使用string拼接
    String details="----------零钱通明细-------------";

    //        3.收益入账
    double money = 0;
    double balance = 0;
    Date date = null;
    SimpleDateFormat sdf =new SimpleDateFormat( "yyyy-MM-dd HH:mm");//用于日期格式化


    //      4.消费
    String note ="";//消费说明
    boolean loop =true;



//菜单
    public void mainMenu()
    {
        do {
            System.out.println("\n==========零钱通菜单===========");
            System.out.println("\t\t\t1 零钱通明细");
            System.out.println("\t\t\t2 收益入账");
            System.out.println("\t\t\t3 消费");
            System.out.println("\t\t\t4 退     出");

            System.out.println("请选择1-4");
            key = myscanner.next();
//使用switch分支控制
            switch (key){
                case "1":
                    this.detail();
                    break;
                case "2":
                    this.income();
                    break;
                case  "3":
                   this.pay();
                   break;
                case "4":
                this.exit();
                break;
                default:
                    System.out.println("选择有误，请重新选择");
            }
        }while (loop);
    }



//零钱通明细
    public void detail(){
        System.out.println(details);
    }




//收益入账
    public void income(){
        System.out.println(" 收益入账金额");
        money = myscanner.nextDouble();
        //找出不正确的金额
        if(money<=0){
            System.out.println("收益入账金额 需要 大于 0");
            return;
        }
        //找出正确的金额
        balance += money;
        date = new Date();//获取当前的日期
        details +="\n收益入账\t" + money +"\t"+sdf.format(date)+"\t"+balance ;
    }





    //消费
public void pay(){
        System.out.println("消费金额");
        money = myscanner.nextDouble();
        if (money<=0||money > balance){
            System.out.println("消费金额应该在0-"+balance);
            return;
        }
        System.out.println("请输入消费说明");
        note = myscanner.next();
        balance -=money;
        details +="\n" + note +"\t-"+money+"\t"+sdf.format(date)+"\t"+balance ;
    }






    //退出
    public void exit(){
        String choice ="";
        while (true){
            System.out.println("你确定要退出吗？y/n");
            choice = myscanner.next();
            if ("y".equals(choice)||"n".equals(choice)){
                break;
            }
        }
        if (choice.equals("y")) {
            loop = false;
        }
    }
}
